//
//  ASPersonCell.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/1/22.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASPersonCell.h"
#import "ASPublicDefine.h"


@interface ASPersonCell()

@property (nonatomic, strong) UIImageView    *leftImage;
@property (nonatomic, strong) UILabel        *rightName;
@property (nonatomic, strong) UIImageView    *topLine;
@property (nonatomic, strong) UIImageView    *bottomLine;

@end


@implementation ASPersonCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        CGFloat fontSize = 16;
        CGFloat padding = 17;
        CGFloat bgWidth = [[UIScreen mainScreen] bounds].size.width;
        
        // leftImage
        _leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(padding,
                                                                   (50 - 19) / 2,
                                                                   19,
                                                                   19)];
        [self.contentView addSubview:_leftImage];
        
        
        // rightName
        _rightName = [[UILabel alloc] initWithFrame:CGRectMake(padding + _leftImage.frame.size.width + 15,
                                                               (50 - 22) / 2,
                                                               bgWidth - (_leftImage.frame.origin.x + _leftImage.frame.size.width) - 15,
                                                               22)];
        [_rightName setBackgroundColor:[UIColor clearColor]];
        [_rightName setTextColor:RGB(51, 51, 51)];
        _rightName.font = [UIFont systemFontOfSize:fontSize];
        [self.contentView addSubview:_rightName];
        
        // separateLine
        UIImageView* separateLine = [[UIImageView alloc] initWithFrame:CGRectMake(50,
                                                                              50 - 1,
                                                                              bgWidth - 80,
                                                                              1)];
        [separateLine setBackgroundColor:[UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0]];
        [self.contentView addSubview:separateLine];
        
        // topLine
        _topLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, bgWidth, 1)];
        [_topLine setBackgroundColor:RGB(221.0, 221.0, 221.0)];
        [self.contentView addSubview:_topLine];
        
        // bottomLine
        _bottomLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, 50 - 1, bgWidth, 1)];
        [_bottomLine setBackgroundColor:RGB(221.0, 221.0, 221.0)];
        [self.contentView addSubview:_bottomLine];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (void)updateCellStatus:(NSString *)imageName cellName:(NSString *)name rowIndex:(NSInteger)row
{
    _leftImage.image = [UIImage imageNamed:imageName];
    _rightName.text = name;
    
    if (0 == row)
    {
        _topLine.hidden = NO;
        _bottomLine.hidden = YES;
    }
    else if (3 == row)
    {
        _topLine.hidden = YES;
        _bottomLine.hidden = NO;
    }
    else
    {
        _topLine.hidden = YES;
        _bottomLine.hidden = YES;
    }
}

@end
